<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use DB;
use App\Http\Controllers\Controller;

class DevController extends Controller
{
    public function getAddone(Request $request){


        $id = $request->session()->get('id');
        $smoke = $this->devInfo('smoke',$id);
        $infrared = $this->devInfo('infrared',$id);
        $gas = $this->devInfo('gas',$id);
        $electric = $this->devInfo('electric',$id);
        $help = $this->devInfo('help',$id);

//        dd($smoke);
        return view('home.dev.add-device1',['smoke'=>$smoke,'infrared'=>$infrared,'gas'=>$gas,'electric'=>$electric,'help'=>$help]);
    }
    public function getAddtwo(Request $request){

        $rec = Db::table('product')->get();
//        dd($rec);
        return view('home.dev.add-device2',['rec'=>$rec]);
    }



    public function getDevsmoke(Request $request){
        $id = $request->session()->get('id');
        return view('home.dev.smoke');
    }
    public function getDevinfrared(){
        return view('home.dev.infrared');
    }
    public function getDevelectric(){
        return view('home.dev.electric');
    }
    public function getDevgas(){
        return view('home.dev.gas');
    }
    public function getDevhelp(){
        return view('home.dev.help');
    }

    //获取个人所有设备信息
    public function devInfo($dev,$member_id){
        //账号下的设备信息
        $data = DB::table($dev)
            ->leftJoin('room_member','room_member.room_id','=',$dev.'.room_id')
            ->where('room_member.member_id',$member_id)
            ->select('num','DevEUI',$dev.'.id')
            ->get();
        return $data;
    }
}